package charlie.demo.bus1.service;

import act.db.beetlsql.BeetlSqlService;
import org.beetl.sql.core.SQLManager;

import javax.inject.Inject;

public class MyService {

    @Inject
    private SQLManager sqlManager;

//    public MyService() {
//        //beetlSql = Act.app().dbServiceManager().dbService("default");
//        this.sqlManager = beetlSqlService.beetlSql();
//    }

    public <T> T single(String sqlid, Class<T> clazz){
        return sqlManager.selectSingle(sqlid, null, clazz);
    }

    public <T> T single(String sqlid, Object parameters, Class<T> clazz){
        return sqlManager.selectSingle(sqlid, parameters, clazz);
    }

    public int singleInt(String sqlid){
        return sqlManager.selectSingle(sqlid, null, Integer.class);
    }

    public int singleInt(String sqlid, Object parameters){
        return sqlManager.selectSingle(sqlid, parameters, Integer.class);
    }

    public long singleLong(String sqlid){
        return sqlManager.selectSingle(sqlid, null, Long.class);
    }

    public long singleLong(String sqlid, Object parameters){
        return sqlManager.selectSingle(sqlid, parameters, Long.class);
    }

    public double singleDouble(String sqlid){
        return sqlManager.selectSingle(sqlid, null, Double.class);
    }

    public double singleDouble(String sqlid, Object parameters){
        return sqlManager.selectSingle(sqlid, parameters, Double.class);
    }

    public String singleString(String sqlid){
        return sqlManager.selectSingle(sqlid, null, String.class);
    }

    public String singleString(String sqlid, Object parameters){
        return sqlManager.selectSingle(sqlid, parameters, String.class);
    }

    public int insert(Object obj){
        return sqlManager.insertTemplate(obj);
    }
}
